<template>
	<!-- 权限添加 -->
	<div>
		<div class="edit-top">
			添加信息
			<i class="el-icon-close" @click='cancel'></i>
		</div>
		<div class="edit-content">
			<div class="edit-title">权限信息</div>
			<div class="edit-item">
				<label>权限名称</label><input v-model="info.permissionName" type="text" />
			</div>
			<div class="edit-item">
				<label>URL</label><input v-model="info.url" type="text" />
			</div>
			<div class="edit-item">
				<label>排序</label><input v-model="info.orderNum" type="number" />
			</div>
			<div class="edit-item">
				<label>perms</label><input v-model="info.perms" type="text" />
			</div>
			<div class="edit-item">
				<label>所属权限</label><el-select v-model="info.parentId" filterable placeholder="请选择">
						<el-option
						  v-for="item in per_list"
						  :key="item.id"
						  :label="item.permissionName"
						  :value="item.id">
						</el-option>
					  </el-select>
			</div>
			<div class="edit-item">
				<label>请求方式</label><select v-model="info.method">
				<option value="GET">GET</option>
				<option value="POST">POST</option>
				<option value="DELETE">DELETE</option>
				</select>
			</div>
			<div class="edit-item">
				<label>类型</label><select v-model="info.permissionType">
				<option value="0">目录</option>
				<option value="1">菜单</option>
				<option value="2">按钮</option>
				</select>
			</div>

		</div>
		<div class="edit-bottom">
			<span @click='cancel'>取消</span>
			<el-button @click='save' type="primary">保存</el-button>
		</div>
	</div>
</template>

<script>
	import Global from '@/components/Global.vue'
	export default {
		data() {
			return {
				per_list:[],
				info: {
					permissionName: '',
					url: '',
					parentId: '',
					url:'',
					method:'get',
					permissionType:0,
					orderNum:1,
					perms:''
				}
			}
		},
		mounted() {
			this.get_per_list();
		},
		methods: {
			get_per_list(){
				var self = this;
				this.$axios.get(this.$global.serverIp + 'admin/permission/selectAll')
					.then(function(res) {
						if (res != '') {
							self.per_list = res.data;
						}
				
					})
			},
			save() {
				if (this.info.permissionName == "") {
					this.$popup.open('权限名称不能为空');
					return;
				}
				if (this.info.url == "") {
					this.$popup.open('url不能为空');
					return;
				}
				var self = this;
				this.$axios.post(this.$global.serverIp + 'admin/permission/save', self.info)
					.then(function(res) {
						if (res != '') {
							self.success('添加成功');
						}
					})
				
			},
			success(content) {
				var self = this;
				this.$alert(content, '提示', {
					confirmButtonText: '确定',
					callback: action => {
						self.$emit("saveAdd", 2);
					}
				});
			},
			cancel() {
				this.$emit("saveAdd", 1);
			}
		}
	}
	import '@/assets/css/edit.css'
</script>
